package com.itheima.d5_resource;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class MyConnection implements AutoCloseable {
    @Override
    public void close() throws Exception {
        System.out.println("释放了与某个硬件的链接资源~~~~");
    }

    public static void main(String[] args) {
        String source = "D:\\test\\source\\th.jfif";
        String dest = "D:\\test\\dest\\itheima1.jfif";


        try (FileInputStream fis = new FileInputStream(source);
             //创建输出流对象关联目标文件
             FileOutputStream fos = new FileOutputStream(dest);
             //创建释放数据流对象
             MyConnection myConnection = new MyConnection()) {
            copyFile1(fis, fos);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Exception");
        }
    }


    public static void copyFile1(FileInputStream fis, FileOutputStream fos) throws IOException {
        int date = -1;
        while ((date = fis.read()) != -1) {
            fos.write(date);
        }

    }


}
